package com.harvey.coding.lambda.file;

import java.io.*;

public class FileService {
    public void handleFile(String url, HandleFileContentsMethod handleMethod){
        try{
            BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(url), "UTF-8"));
            StringBuilder lineSb = new StringBuilder();
            String singleLine;
            while (null != (singleLine = reader.readLine())){
                lineSb.append(singleLine + "\n");
            }
            handleMethod.handle(lineSb.toString());
        }catch (FileNotFoundException | UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
